package com.sf.fy.uav.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sf.fy.uav.common.awt.JwtUtil;
import com.sf.fy.uav.entity.CouponActivity;
import com.sf.fy.uav.entity.CouponActivityRecord;
import com.sf.fy.uav.mapper.CouponActivityRecordMapper;
import com.sf.fy.uav.service.ICouponActivityRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 订单商品关联表 服务实现类
 * </p>
 *
 * @author LTQ
 * @since 2024-08-27
 */
@Service
public class CouponActivityRecordServiceImpl extends ServiceImpl<CouponActivityRecordMapper, CouponActivityRecord> implements ICouponActivityRecordService {

    @Autowired
    private CouponActivityRecordMapper couponActivityRecordMapper;

    @Override
    public Long getRecordCnt(String couponActivityId, String userId) {
        QueryWrapper<CouponActivityRecord> couponActivityRecordQueryWrapper = new QueryWrapper<>();
        couponActivityRecordQueryWrapper.eq("coupon_activity_id", couponActivityId);
        couponActivityRecordQueryWrapper.eq("user_id", userId);
        return couponActivityRecordMapper.selectCount(couponActivityRecordQueryWrapper);
    }

    @Override
    public List<CouponActivityRecord> getNewerRecord(String userId) {
        QueryWrapper<CouponActivityRecord> couponActivityRecordQueryWrapper = new QueryWrapper<>();
        couponActivityRecordQueryWrapper.eq("user_id", userId);
        couponActivityRecordQueryWrapper.eq("displayed", false);
        return couponActivityRecordMapper.selectList(couponActivityRecordQueryWrapper);
    }

    @Override
    public List<CouponActivityRecord> selByCouponActivityIds(List<String> couponActivityIds, Integer page, Integer pageSize) {
        LambdaQueryWrapper<CouponActivityRecord> couponActivityRecordQueryWrapper = new QueryWrapper<CouponActivityRecord>().lambda().in(CouponActivityRecord::getCouponActivityId, couponActivityIds);
        return couponActivityRecordMapper.selectPage(new Page<>(page, pageSize), couponActivityRecordQueryWrapper.orderByDesc(CouponActivityRecord::getCreateTime)).getRecords();
    }

    @Override
    public Long countByCouponActivityIds(List<String> couponActivityIds) {
        LambdaQueryWrapper<CouponActivityRecord> couponActivityRecordQueryWrapper = new QueryWrapper<CouponActivityRecord>().lambda().in(CouponActivityRecord::getCouponActivityId, couponActivityIds);
        return couponActivityRecordMapper.selectCount(couponActivityRecordQueryWrapper);
    }
}
